// pages/twozc/twozc.js
const app = getApp();
Page({
  data: {
    openid:'',
    mealsList: '',
    USER_ASSETS_NAME: '',//姓名

    EMPLOYEE_ID: '',//工号
    showView: false,

    yuangong: '',
    USER_COUPON_PHONE: '',//手机号

    flag: true,//节流
    UUIDSTRING:'',
  },



  //拿到员工id
  onLoad: function (e) {
    console.log(e);
    this.setData({
      mealsList: app.globalData.mealsList,
      UUIDSTRING: app.globalData.UUIDSTRING,
      openid: app.globalData.openid,
      jiami: app.globalData.jiami,
      OPEN_ID: app.globalData.openid,
      session_key: app.globalData.session_key,
      
    });
    console.log(e.data);
    var yuan = e.data
    this.setData({
      yuangong: yuan
    })
    console.log(this.data.yuangong);
    console.log(this.data.mealsList);

  },


  //判断输入框是否有数据

  jump: function () {
    if (!this.data.USER_ASSETS_NAME || !this.data.USER_COUPON_PHONE || !this.data.mealsList) {
      console.log(this.data.USER_ASSETS_NAME);
      console.log(this.data.USER_COUPON_PHONE);
      console.log(this.data.mealsList);
      wx.showModal({
        title: '温馨提示',
        content: '请完善信息',
        success: function (res) {
          if (res.confirm) {//这里是点击了确定以后   
            console.log('用户点击确定')
          } else {//这里是点击了取消以后
            console.log('用户点击取消')
          }
        }
      })

    } else {
      this.setData({
        showView: (!this.data.showView)
      })
    }
  },

  //跳转回去
  quno: function () {
    wx.redirectTo({
      url: '../../pages/akweiyoufukaihuxinzen/akweiyoufukaihuxinzen'
    })
  },


  //点击确定以后向后台传数据
  tjok: function () {
    if (this.data.flag) {
      console.log(111);
     
    wx.request({
      url: app.globalData.interface+'/ankang/API_2007_AnKangAccountOpeningGiftAdd',
      method: 'POST',
      data: {
        USER_ASSETS_NAME: this.data.USER_ASSETS_NAME,//姓名
        USER_ASSETS_IDCARD: this.data.USER_COUPON_PHONE,//手机号
        EMPLOYEE_ID: this.data.mealsList,//员工工号
        OPEN_ID: this.data.openid, //用户OPEN_ID
        session_key:this.data.session_key,
        OPEN_UUID:this.data.jiami

      },
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: function (res) {
        console.log(res.data);
        if (res.data.result != 'success') {
          wx.showModal({
            title: '温馨提示',
            content: res.data.data,
            success: function (res) {
              if (res.confirm) {//这里是点击了确定以后
                console.log('用户点击确定')
              } else {//这里是点击了取消以后
                console.log('用户点击取消')
              }
            }
          })
        } else {
          wx.showModal({
            title: '温馨提示',
            content: res.data.data,
            success: function (res) {
              if (res.confirm) {//这里是点击了确定以后
                console.log('用户点击确定')
                wx.redirectTo({
                  url: '../../pages/shangbangka/shangbangka'
                })
              } else {//这里是点击了取消以后
                console.log('用户点击取消')
                wx.redirectTo({
                  url: '../../pages/shangbangka/shangbangka'
                })
              }
            }
          })
        }
      }
    })
    this.data.flag = false
    setTimeout(() => {
      console.log('-----------------',1);
      this.data.flag = true
    }, 5000)




  }
  },




  //验证手机号
  mobileInput(e) {
    let value = e.detail.value.replace(/\D/g, '')
    this.setData({
      mobile: value,
    })
    // var myreg = /^(((13[0-9]{1})|(15[0-9]{1})|(16[0-9]{1})|(19[0-9]{1})|(18[0-9]{1})|(17[0-9]{1}))+\d{8})$/;
    var myreg = /^(((13[0-9]{1})|(14[0-9]{1})|(15[0-9]{1})|(16[0-9]{1})|(19[0-9]{1})|(18[0-9]{1})|(17[0-9]{1}))+\d{8})$/;
    if (this.data.mobile.length == 0) {
      wx.showToast({
        title: '输入的手机号为空，请重新输入！',
        icon: 'none',
        duration: 1500
      })
      this.setData({
        mobileFormat: false,
      })
    } else if (this.data.mobile.length < 11) {

      wx.showToast({
        title: '手机号长度有误，请重新输入！',
        icon: 'none',
        duration: 1500
      })
      this.setData({
        USER_COUPON_PHONE: '',
        mobileFormat: false,
      })

    } else if (!myreg.test(this.data.mobile)) {
      wx.showToast({
        title: '手机号有误，请重新输入！',
        icon: 'none',
        duration: 1500
      })
      this.setData({
        USER_COUPON_PHONE: '',
        mobileFormat: false,
      })

    } else {
      this.setData({
        mobileFormat: true,
      })
    }
  },









  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {


  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

    //如果没数据就跳回登录页  

    // if (!this.data.mealsList) {
    //   wx.navigateTo({
    //     url: '../../pages/bjygdenglu/bjygdenglu'
    //   })
    // }



  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})